/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/game_playing.h"
#include "PlanetWars2dRT-core/specific/model/game_default.h"


EXTERN_C_BEGIN


void
game_playing_init_first_time_only_data(game_playing_t* a_game_playing)
{
  a_game_playing->data             = NULL;
  a_game_playing->data_free        = NULL;
}

void
game_playing_init_first_time_only_functions(game_playing_t* a_game_playing)
{
  a_game_playing->do_if_not_paused = NULL;
  a_game_playing->do_always        = NULL;
}

bool
game_playing_init_first_time_only(game_playing_t* a_game_playing)
{
  if(a_game_playing == NULL)
    {
      return false;
    }
  
  game_init_first_time_only      (&a_game_playing->game);
  game_state_init_first_time_only(&a_game_playing->state);
  game_playing_init_first_time_only_data     (a_game_playing);
  game_playing_init_first_time_only_functions(a_game_playing);
  return true;
}

bool
game_playing_init_first_time_only_default(game_playing_t* a_game_playing)
{
  if(!game_playing_init_first_time_only(a_game_playing))
    {
      return false;
    }
  game_set_default(&a_game_playing->game);
  return true;
}

void
game_playing_destructor(game_playing_t* a_game_playing)
{
  if(a_game_playing != NULL)
    {
      game_destructor      (&a_game_playing->game);
      game_state_destructor(&a_game_playing->state);
      
      if(a_game_playing->data      != NULL &&
	 a_game_playing->data_free != NULL)
	{
	  a_game_playing->data_free(a_game_playing->data);
	}
    }
}


EXTERN_C_END
